import Utils from "../../../utils/index.js"
export default class Observer{
    constructor(obj){
        //console.log(obj)
        monitorPropertyReadAndWrite(obj)
        return obj;
    }
    
}
function monitorPropertyReadAndWrite(obj){
    //console.log(Utils.getType(obj))
    if( Utils.getType(obj)  == "Object" ){
        //console.log(Object.keys(obj))
        Object.keys(obj).map(key=>{
            //console.log(Utils.getType(obj[key]))
            if( Utils.getType(obj[key]) == "Object" ) {
                //console.log("over flow")
                monitorPropertyReadAndWrite(obj[key])
            }
            let tempValue = obj[key];
            Object.defineProperty(obj,key,{
                enumerable: true,
                configurable: true,
                get(){
                    console.log(`${key}属性被读取了`)
                    return tempValue;
                },
                set(newVal){
                    console.log(`${key}属性被设置了`)
                    if(tempValue == newVal) return ;
                    tempValue = newVal;
                }
            })
        })
        obj.__b__ = true;
        //console.log(`${obj}`,`${obj.__b__}`)
    } 
}